import geopandas as gpd
import pandas as pd
import datetime

inf=gpd.read_file('C:/Users/18295335197/Desktop/test/全省病例日期恢复.geojson')
gdf=gpd.read_file('C:/Users/18295335197/Desktop/test/湖北省乡镇街道病例.geojson')
gdf['pop'].fillna(0,inplace=True)
gdf['pop'].astype('int')
for einf in inf.groupby('onset_date'):
    date=einf[0]
    df=pd.DataFrame(einf[1])
    df = gpd.GeoDataFrame(df, geometry='geometry')
    sj_gdf= gpd.sjoin(gdf, df, how='left', op='intersects', lsuffix='left', rsuffix='right')
    gdf_sj = sj_gdf['id'].groupby([sj_gdf['Id']]).count()
    gdf = gdf.join(gdf_sj, on='Id')
    gdf.rename(columns={'id': date}, inplace=True)
    gdf[date].fillna(0,inplace=True)
    #df[date]=gdf[date]/(gdf['pop']+0.0001)*10000
gdf.to_file('C:/Users/18295335197/Desktop/test/fix/湖北省乡镇街道每日病例.geojson',driver='GeoJSON', encoding='utf-8')
print(gdf)
